package com.pjj.messageservice.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pjj.base.base.utils.ResponseUtil;
import com.pjj.messageservice.entity.Message;
import com.pjj.messageservice.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 76004
 * @apiNote
 * @date 2023/2/27 19:57
 */
@Service
public class MessageService {
    @Autowired
    private MessageMapper messageMapper;

    public Object sendMessage(Message message) {
        messageMapper.insert(message);
        return ResponseUtil.success();
    }

    public Object deleteById(long id) {
        messageMapper.deleteById(id);
        return ResponseUtil.success();
    }

    public Object selectBySenderId(String senderId, int pageNum, int pageSize) {
        return ResponseUtil.success(
                messageMapper.selectPage(new Page<Message>(pageNum, pageSize),
                        new QueryWrapper<Message>().eq("sender", senderId)));
    }

    public Object selectByRecipientId(String recipientId, int pageNum, int pageSize){
        return ResponseUtil.success(messageMapper.selectPage(new Page<Message>(pageNum, pageSize),
                new QueryWrapper<Message>().eq("recipients", recipientId)));
    }

    public Object replyMessage(Message message){
        return ResponseUtil.success(messageMapper.insert(message));
    }




}
